package com.ruoyi.jiuzai.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.jiuzai.domain.Wuziruku;
import com.ruoyi.jiuzai.service.IWuzirukuService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * wuzirukuController
 * 
 * @author ruoyi
 * @date 2025-06-20
 */
@RestController
@RequestMapping("/jiuzai/wuziruku")
public class WuzirukuController extends BaseController
{
    @Autowired
    private IWuzirukuService wuzirukuService;

    /**
     * 查询wuziruku列表
     */
    @PreAuthorize("@ss.hasPermi('jiuzai:wuziruku:list')")
    @GetMapping("/list")
    public TableDataInfo list(Wuziruku wuziruku)
    {
        startPage();
        List<Wuziruku> list = wuzirukuService.selectWuzirukuList(wuziruku);
        System.out.println("数据----"+list);
        return getDataTable(list);
    }

    /**
     * 导出wuziruku列表
     */
    @PreAuthorize("@ss.hasPermi('jiuzai:wuziruku:export')")
    @Log(title = "wuziruku", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Wuziruku wuziruku)
    {
        List<Wuziruku> list = wuzirukuService.selectWuzirukuList(wuziruku);
        ExcelUtil<Wuziruku> util = new ExcelUtil<Wuziruku>(Wuziruku.class);
        util.exportExcel(response, list, "wuziruku数据");
    }

    /**
     * 获取wuziruku详细信息
     */
    @PreAuthorize("@ss.hasPermi('jiuzai:wuziruku:query')")
    @GetMapping(value = "/{rukuId}")
    public AjaxResult getInfo(@PathVariable("rukuId") Long rukuId)
    {
        System.out.println("数据----"+wuzirukuService.selectWuzirukuByRukuId(rukuId));
        return success(wuzirukuService.selectWuzirukuByRukuId(rukuId));
    }

    /**
     * 新增wuziruku
     */
    @PreAuthorize("@ss.hasPermi('jiuzai:wuziruku:add')")
    @Log(title = "wuziruku", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Wuziruku wuziruku)
    {
        // 修改前：
        // return toAjax(wuzirukuService.insertWuziruku(wuziruku));

        // 修改后：
        int rows = wuzirukuService.insertWuziruku(wuziruku);
        if (rows > 0) {
            // 返回包含生成ID的完整实体
            return success(wuziruku);
        }
        return error("新增失败");
    }

    /**
     * 修改wuziruku
     */
    @PreAuthorize("@ss.hasPermi('jiuzai:wuziruku:edit')")
    @Log(title = "wuziruku", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Wuziruku wuziruku)
    {
        return toAjax(wuzirukuService.updateWuziruku(wuziruku));
    }

    /**
     * 删除wuziruku
     */
    @PreAuthorize("@ss.hasPermi('jiuzai:wuziruku:remove')")
    @Log(title = "wuziruku", businessType = BusinessType.DELETE)
	@DeleteMapping("/{rukuIds}")
    public AjaxResult remove(@PathVariable Long[] rukuIds)
    {
        return toAjax(wuzirukuService.deleteWuzirukuByRukuIds(rukuIds));
    }
}
